package com.github.cbyzzy.callback;

/**
 * @Name: AlarmInitializer
 * @Author: HenryWong 549264639@qq.com
 * @Date: 2024-12-12 18:28
 */

import com.github.cbyzzy.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

//@Component
public class AlarmInitializer implements ApplicationRunner {

    @Autowired
    private AlarmService alarmService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 初始化SDK及相关设置
        alarmService.initSDKAndSettings();

        // 示例中使用固定的设备登录信息，实际可配置化
        String ip = "192.168.100.201";
        short port = 8000;
        String name = "admin";
        String password = "abc12345";

        // 登录设备
        int lUserID = alarmService.loginDevice(ip, port, name, password);
        if (lUserID >= 0) {
            // 设置报警回调函数
            alarmService.setAlarmCallback();
            // 建立报警上传通道（布防）
            int nativeLong = alarmService.setupAlarmChan(lUserID);
            if (nativeLong >= 0) {
                // 这里可以添加后续业务逻辑，比如持续监听报警信息等，示例中暂不详细展开

            }
        }
    }
}
